package project3t.android.control;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import project3t.android.data.Person;
import project3t.android.rest.RestConnect;


public class Controller {

	private List<Person> people;	
	public static Controller conroller=new Controller();

	private Controller()
	{	   
		people=new LinkedList<Person>();
		for(int i=0; i<15;i++)
		{
			Person p=new Person();
			p.setId(new Long(i));
			p.setName("name"+i);
			p.setSurname("surname"+i);
			p.setAge(i);
			p.setSex((i%2==0)?'F':'M');
			people.add(p);
		}
	}
	
	public Person getPersonByPos(int position)
	{
		//Connection.connection.f();
		return people.get(position);
	}

	public List<Person> getPeople()
	{	
		
		//List people2=RestConnect.makeRequest();		
		return people;
	}
	   
	public void setPeople(List<Person> persons)
	{
		people.clear();
	    for (Person person:persons)
	    {
	    	people.add(person);	    
	    }
	}

	public void deletePerson(int index)
	{		
	    people.remove(index);
	}

	public void editPerson(int index, Person person)
	{
		people.set(index, person);
	}

	public void addPerson(String[] fields)
	{
		Person newPerson=new Person();
		people.add(newPerson);
	}
}
